package com.example.androidhive;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListViewAdapter extends BaseAdapter {

	private Activity activity;
	private ArrayList<HashMap<String, String>> data;
	private static LayoutInflater inflater = null;

	public ListViewAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
		activity = a;
		data = d;
		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public int getCount() {
		return data.size();
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}
	
	
	//add22222222222222222222
	

	
	
	
	
	static class ViewHolder {
		protected TextView name;
		protected TextView sdt;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;
		ViewHolder holder = new ViewHolder();
		if (convertView == null)
			vi = inflater.inflate(R.layout.list_item, null);

		
		holder.name = (TextView) vi.findViewById(R.id.name);
		holder.sdt = (TextView) vi.findViewById(R.id.sdt);
		 HashMap<String, String> item = new HashMap<String, String>();
		 item = data.get(position);
		 holder.name.setText(item.get("name"));
		 holder.sdt.setText(item.get("sdt"));
		 return vi;
		 
		 
		// TextView name = (TextView)vi.findViewById(R.id.name); // title
		// HashMap<String, String> item = new HashMap<String, String>();
		// item = data.get(position);
		// name.setText(item.get("name"));
		// return vi;
	}

	public void add(HashMap<String, String> map) {
		// TODO Auto-generated method stub
		data.add(map);
		notifyDataSetChanged();
	}

	

}